package com.waiting.thread;

/**
 * @Description
 * @Author bjweitingting
 * @Date 2019/3/8
 **/
public class MinCostClimbingStairs746 {
    public static void main(String[] args) {
        int[] cost = {1, 100, 1, 1, 1, 100, 1, 1, 100, 1};
        System.out.println(minCostClimbingStairs(cost));
    }

    public static int minCostClimbingStairs(int[] cost) {
        if (cost == null || cost.length < 3) {
            return 0;
        }
        int[] tmp = new int[cost.length];
        tmp[0] = 0;
        tmp[1] = 0;
        int i = 0;
        for (i = 2; i < cost.length - 1; i++) {
            tmp[i] = Math.min((tmp[i - 1] + cost[i - 1]), (tmp[i - 2] + cost[i - 2]));
        }
        //最后一步
        tmp[i] = Math.min((tmp[i - 1] + cost[i - 1]), (tmp[i - 2] + cost[i - 2] + cost[i]));
        return tmp[cost.length - 1];
    }
}
